import 'package:flutter/cupertino.dart';
import 'package:get/get.dart';
import 'package:seedfour/app/models/invite_settles_entity.dart';

import '../../../services/api_service.dart';

class MineInviteSettlesLogic extends GetxController {
  final apiService = Get.find<ApiService>();
  final loadingTip = '加载中...';
  final noMoreTip = '没有更多了';

  var isLoading = true.obs;
  var bottomTips = ''.obs;
  var inviteSettles = <InviteSettlesData>[].obs;

  final scrollController = ScrollController();

  final pageSize = 20;
  int _page = 1;

  @override
  void onInit() {
    super.onInit();
    scrollController.addListener(() {
      if (scrollController.position.pixels ==
          scrollController.position.maxScrollExtent) {
        bottomTips.value = loadingTip;
        _getInviteSettles();
      }
    });

    _getInviteSettles();
  }

  void _getInviteSettles() {
    inviteSettles.clear();
    apiService.getInviteSettleList(_page, pageSize).then((invite) => {
          isLoading.value = false,
          _page++,
          if (invite != null)
            {
              inviteSettles.addAll(invite.data ?? []),
              bottomTips.value = noMoreTip
            }
          else
            {bottomTips.value = noMoreTip}
        });
  }
}
